#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
#TODO: documentation!
"""

__version__ = '$Id$'

from pyglet.gl import *

class View(object):
    """
    Represents a viewport of the world.
    """
    def __init__(self,
                state,
                world_pos=(0.0, 0.0, 1.0),
                world_dir=(0.0, 0.0, 0.0),
                screen_pos=(0.0, 0.0),
                screen_size=(640.0, 480.0),
                far=10.0):
        self.x, self.y, self.z = world_pos
        self.rx, self.ry, self.rz = world_dir
        self.screen_x, self.screen_y = screen_pos
        self.screen_w, self.screen_h = screen_size
        self._far = far
        
    def on_resize(self, width, height):
        self.screen_w, self.screen_h = width, height
        
    def set_viewport(self):
        """
        Sets this viewport as the current render target.
        """
        glViewport( int(self.screen_x), int(self.screen_y), int(self.screen_w), int(self.screen_h))
        glMatrixMode( gl.GL_PROJECTION )
        glLoadIdentity()
        glOrtho( -self.screen_w/2., self.screen_w/2., -self.screen_h/2., self.screen_h/2.,-1, 10)
        glMatrixMode( gl.GL_MODELVIEW )
        
